﻿package desk.game.eatbean;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
	
public class MyMIDlet extends MIDlet implements CommandListener{
	Display display;
	MyCanvas mc;
	private Command cmdRest;
	private Command cmdExit;
	public MyMIDlet()
	{
		mc=new MyCanvas();
		display=Display.getDisplay(this);
		cmdRest=new Command("下一关",Command.OK,2);
		cmdExit=new Command("Exit",Command.EXIT,1);
		mc.addCommand(cmdRest);
		mc.addCommand(cmdExit);
		mc.setCommandListener(this);
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

	}

	protected void pauseApp() {

	}

	protected void startApp() throws MIDletStateChangeException {
		display.setCurrent(mc);
	}

	public void commandAction(Command c, Displayable d) {
		if(c==cmdExit)
		{
			try {
				destroyApp(false);
				notifyDestroyed();
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
		}
		if(c==cmdRest)
		{
			mc.rest();
			mc=new MyCanvas();
			display=Display.getDisplay(this);
			cmdRest=new Command("下一关",Command.OK,2);
			cmdExit=new Command("Exit",Command.EXIT,1);
			mc.addCommand(cmdRest);
			mc.addCommand(cmdExit);
			mc.setCommandListener(this);
			try {
				startApp();
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
		}
	}




}
